#pragma once
//==============================================================================================================
#include "Configuration.h"


//==============================================================================================================

#if SYSTEM_CONFIG == 1

//// Thermistor settings:
// 1 is 100k thermistor
// 2 is 200k thermistor
// 3 is mendel-parts thermistor
// 4 is 10k thermistor
// 5 is ParCan supplied 104GT-2 100K
// 6 is EPCOS 100k
// 7 is 100k Honeywell thermistor 135-104LAG-J01
#define THERMISTORHEATER 1
#define THERMISTORBED 1


#define _AXIS_STEP_PER_UNIT { 88.89, 88.89 , 1055.959, 102.15 }	// STEPS PER UNITS
//---------------------------------------------------------------------------------
#define SLEEP_MODE_ON
#define NUM_AXIS 4
#define _MAX_FEEDRATE {400, 400, 1000, 450000}       // (mm/sec) //Z 2 E 45
#define _HOMING_FEEDRATE {1500,1500,350}      // (mm/min) !!
#define _AXIS_RELATIVE_MODES {false, false, false, false}
#define _CHANGE_TOOL_FEEDRATE 3000
#define _ACCELERATION 1000         // Axis Normal acceleration mm/s^2
#define _RETRACT_ACCELERATION 2000 // Extruder Normal acceleration mm/s^2
#define JERK_DIV 500.0f				// Delitel pro vypocet jerku pro vsechny osy, se zmenami velmi opatrne
#define _MAX_ACCELERATION_UNITS_PER_SQ_SECOND {5000,5000,50,5000}    // X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts
//------------------------------------------------------------------------------
#define X_ENDSTOP_INVERT true
#define Y_ENDSTOP_INVERT true
#define Z_ENDSTOP_INVERT true
//------------------------------------------------------------------------------
#define SDSUPPORT
#define SDINITFILE
//------------------------------------------------------------------------------
#define X_ENABLE_ON 0
#define Y_ENABLE_ON 0
#define Z_ENABLE_ON 0
#define E1_ENABLE_ON 0
#define E2_ENABLE_ON 0
//------------------------------------------------------------------------------
#define SLEEP_X 1
#define SLEEP_Y 1
#define SLEEP_Z 1
#define SLEEP_E 1
//------------------------------------------------------------------------------
#define X_HOME_DIR -1
#define Y_HOME_DIR -1
#define Z_HOME_DIR -1
//------------------------------------------------------------------------------
#define INVERT_X_DIR 1
#define INVERT_Y_DIR 1
#define INVERT_Z_DIR 1
#define INVERT_E_DIR 1
//If true, axis won't move to coordinates less than zero.
#define min_software_endstops  false
//If true, axis won't move to coordinates greater than the defined lengths below.
#define max_software_endstops  true
//------------------------------------------------------------------------------
#define X_MAX_LENGTH 150
#define Y_MAX_LENGTH 150
#define Z_MAX_LENGTH 150
#define MAX_STEP_FREQUENCY 30000 // Max step frequency
//------------------------------------------------------------------------------
#define MAX_RETRACT_FEEDRATE 100    //mm/sec
#define EXTRUDERS_COUNT 2
#define _EXTRUDER1_OFFSETS { 0.0, 0.0 }
#define _EXTRUDER2_OFFSETS { 66.0, 0.0 }
//-----------------------------------------------------------------------
#define _DEFAULT_STEPPER_INACTIVE_TIME 60000
#define _DEFAULT_MAX_INACTIVE_TIME 300000
// Minimum planner junction speed. Sets the default minimum speed the planner plans for at the end
// of the buffer and all stops. This should not be much greater than zero and should only be changed
// if unwanted behavior is observed on a user's machine when running at very slow speeds.
#define MINIMUM_PLANNER_SPEED 0.05 // (mm/sec)

#define DEFAULT_MINIMUMFEEDRATE       0.0     // minimum feedrate
#define DEFAULT_MINTRAVELFEEDRATE     0.0

#define _MIN_SEG_TIME 20000

// If defined the movements slow down when the look ahead buffer is only half full
// Tato funkce nepni dobre svoji ulohu, protoze pri zmene rychlosti nedochazi ke spojovani pohybu, bude opraveno
//#define SLOWDOWN

//everything with less than this number of steps will be ignored as move and joined with the next movement
#define dropsegments  5 

//-----------------------------------------------------------------------
// Machine UUID
//-----------------------------------------------------------------------
// This may be useful if you have multiple machines and wish to identify them by using the M115 command. 
// By default we set it to zeros.
// Nutno se domluvit jestli to k necemu je
#define _DEF_CHAR_UUID "00000000-0000-0000-0000-000000000000"
#define _DEF_MACHINE_NAME "FIRMWARE_NAME: 3DFactories PROTOCOL_VERSION:1.02 MACHINE_TYPE:EASY3DMAKER EXTRUDER_COUNT:2"



//-----------------------------------------------------------------------
//// Planner buffer Size
//-----------------------------------------------------------------------

// The number of linear motions that can be in the plan at any give time
// if the SD Card need to much memory reduce the Values for Plannerpuffer (base of 2)
#ifdef SDSUPPORT
  #define BLOCK_BUFFER_SIZE 16
  #define BLOCK_BUFFER_MASK 0x0f
#else
  #define BLOCK_BUFFER_SIZE 16  
  #define BLOCK_BUFFER_MASK 0x0f
#endif 

//-----------------------------------------------------------------------
//// SETTINGS FOR ARC FUNCTION (Command G2/G2)
//-----------------------------------------------------------------------
/*
#define USE_ARC_FUNCTION
// Arc interpretation settings:
//Step to split a cirrcle in small Lines 
#define MM_PER_ARC_SEGMENT 1
//After this count of steps a new SIN / COS caluclation is startet to correct the circle interpolation
#define N_ARC_CORRECTION 25
*/

//==============================================================================
//
// HEATER CONTROL AND PID PARAMETERS
//
//==============================================================================

// Select which extruder are used
#define BED_HEATER_ACTIVE
// musi byt definovano vzdy
#define EXT1_HEATER_ACTIVE
// definovano jen pokud je pouzit druhy extruder
//#define EXT2_HEATER_ACTIVE


//PID Controler Settings
#define PID_INTEGRAL_DRIVE_MAX 80 // too big, and heater will lag after changing temperature, too small and it might not compensate enough for long-term errors
#define PID_PGAIN 2560 //256 is 1.0  // value of X means that error of 1 degree is changing PWM duty by X, probably no need to go over 25
#define PID_IGAIN 64 //256 is 1.0  // value of X (e.g 0.25) means that each degree error over 1 sec (2 measurements) changes duty cycle by 2X (=0.5) units (verify?)
#define PID_DGAIN 4096 //256 is 1.0  // value of X means that around reached setpoint, each degree change over one measurement (half second) adjusts PWM by X units to compensate

// magic formula 1, to get approximate "zero error" PWM duty. Take few measurements with low PWM duty and make linear fit to get the formula
// for my makergear hot-end: linear fit {50,10},{60,20},{80,30},{105,50},{176,100},{128,64},{208,128}
#define HEATER_DUTY_FOR_SETPOINT(setpoint) ((int)((187L*(long)setpoint)>>8)-27)  
	

//==============================================================
//
// FAN CONTROL
//
//==============================================================

// Odkomentovanim se aktivuje rizeni
#define FAN2_AS_CONTROLLERFAN

// Omezeni pwm pro extrudery, 255 = maximum trvale sepnuto
#define EXTRUDER_HEATER_CURRENT_MAX 255

// Omezeni pwm pro topeni desky, 255 == trvale sepnuto
#define BED_HEATER_CURRENT_MAX 255

// How often should the heater check for new temp readings, in milliseconds
#define HEATER_CHECK_INTERVAL 500
#define BED_CHECK_INTERVAL 5000

// Comment the following line to enable heat management during acceleration
#define DISABLE_CHECK_DURING_ACC
#ifndef DISABLE_CHECK_DURING_ACC
  // Uncomment the following line to disable heat management during moves
  //#define DISABLE_CHECK_DURING_MOVE
#endif

// Uncomment the following line to disable heat management during travel moves (and extruder-only moves, eg: retracts), strongly recommended if you are missing steps mid print.
// Probably this should remain commented if are using PID.
// It also defines the max milliseconds interval after which a travel move is not considered so for the sake of this feature.
#define DISABLE_CHECK_DURING_TRAVEL 1000

//// Temperature smoothing - only uncomment this if your temp readings are noisy (Gen6 without EvdZ's 5V hack)
//#define SMOOTHING
//#define SMOOTHFACTOR 16 //best to use a power of two here - determines how many values are averaged together by the smoothing algorithm


//// Experimental watchdog and minimal temp
// The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature
// If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109
//#define WATCHPERIOD 5000 //5 seconds

// Actual temperature must be close to target for this long before M109 returns success
//#define TEMP_RESIDENCY_TIME 20  // (seconds)
//#define TEMP_HYSTERESIS 5       // (C°) range of +/- temperatures considered "close" to the target one

//// The minimal temperature defines the temperature below which the heater will not be enabled
#define MINTEMP 5

//// Experimental max temp
// When temperature exceeds max temp, your heater will be switched off.
// This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure!
// You should use MINTEMP for thermistor short/failure protection.
#define MAXTEMP 275

// Select one of these only to define how the nozzle temp is read.
#define HEATER_USES_THERMISTOR
//#define HEATER_USES_AD595
//#define HEATER_USES_MAX6675

// Select one of these only to define how the bed temp is read.
#define BED_USES_THERMISTOR
#define EXTRUDER1_USE_THERMISTOR
#define EXTRUDER2_USE_THERMISTOR
//#define BED_USES_AD595


#define CONTROLLERFAN_SEC 60 //How many seconds, after all motors were disabled, the fan should run
#define EXTRUDERFAN_DEC 50 //Hotend temperature from where the fan will be turned on
//-----------------------------------------------------------------------
#define SEND_WRONG_CMD_INFO

#endif // END CONFIG 1
//==============================================================================================================================================================
#if SYSTEM_CONFIG == 2

#endif
//===============================================================================================================================================================
#if SYSTEM_CONFIG == 3

#define REMOTE_IO_MASTER
//// Thermistor settings:
// 1 is 100k thermistor
// 2 is 200k thermistor
// 3 is mendel-parts thermistor
// 4 is 10k thermistor
// 5 is ParCan supplied 104GT-2 100K
// 6 is EPCOS 100k
// 7 is 100k Honeywell thermistor 135-104LAG-J01
#define THERMISTORHEATER 1
#define THERMISTORBED 1


#define _AXIS_STEP_PER_UNIT { 88.89, 88.89 , 1055.959, 102.15 }	// STEPS PER UNITS
//---------------------------------------------------------------------------------
#define SLEEP_MODE_ON
#define NUM_AXIS 4
#define _MAX_FEEDRATE {400, 400, 1000, 450000}       // (mm/sec) //Z 2 E 45
#define _HOMING_FEEDRATE {1500,1500,350}      // (mm/min) !!
#define _AXIS_RELATIVE_MODES {false, false, false, false}
#define _CHANGE_TOOL_FEEDRATE 3000
#define _ACCELERATION 1000         // Axis Normal acceleration mm/s^2
#define _RETRACT_ACCELERATION 2000 // Extruder Normal acceleration mm/s^2
#define JERK_DIV 500.0f				// Delitel pro vypocet jerku pro vsechny osy, se zmenami velmi opatrne
#define _MAX_ACCELERATION_UNITS_PER_SQ_SECOND {5000,5000,50,5000}    // X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts
//------------------------------------------------------------------------------
#define X_ENDSTOP_INVERT true
#define Y_ENDSTOP_INVERT true
#define Z_ENDSTOP_INVERT true
//------------------------------------------------------------------------------
#define SDSUPPORT
#define SDINITFILE
//------------------------------------------------------------------------------
#define X_ENABLE_ON 0
#define Y_ENABLE_ON 0
#define Z_ENABLE_ON 0
#define E1_ENABLE_ON 0
#define E2_ENABLE_ON 0
//------------------------------------------------------------------------------
#define SLEEP_X 1
#define SLEEP_Y 1
#define SLEEP_Z 1
#define SLEEP_E 1
//------------------------------------------------------------------------------
#define X_HOME_DIR -1
#define Y_HOME_DIR -1
#define Z_HOME_DIR -1
//------------------------------------------------------------------------------
#define INVERT_X_DIR 1
#define INVERT_Y_DIR 1
#define INVERT_Z_DIR 1
#define INVERT_E_DIR 1
//If true, axis won't move to coordinates less than zero.
#define min_software_endstops  false
//If true, axis won't move to coordinates greater than the defined lengths below.
#define max_software_endstops  true
//------------------------------------------------------------------------------
#define X_MAX_LENGTH 150
#define Y_MAX_LENGTH 150
#define Z_MAX_LENGTH 150
#define MAX_STEP_FREQUENCY 30000 // Max step frequency
//------------------------------------------------------------------------------
#define MAX_RETRACT_FEEDRATE 100    //mm/sec
#define EXTRUDERS_COUNT 2
#define _EXTRUDER1_OFFSETS { 0.0, 0.0 }
#define _EXTRUDER2_OFFSETS { 66.0, 0.0 }
//-----------------------------------------------------------------------
#define _DEFAULT_STEPPER_INACTIVE_TIME 60000
#define _DEFAULT_MAX_INACTIVE_TIME 300000
// Minimum planner junction speed. Sets the default minimum speed the planner plans for at the end
// of the buffer and all stops. This should not be much greater than zero and should only be changed
// if unwanted behavior is observed on a user's machine when running at very slow speeds.
#define MINIMUM_PLANNER_SPEED 0.05 // (mm/sec)

#define DEFAULT_MINIMUMFEEDRATE       0.0     // minimum feedrate
#define DEFAULT_MINTRAVELFEEDRATE     0.0

#define _MIN_SEG_TIME 20000

// If defined the movements slow down when the look ahead buffer is only half full
// Tato funkce nepni dobre svoji ulohu, protoze pri zmene rychlosti nedochazi ke spojovani pohybu, bude opraveno
//#define SLOWDOWN

//everything with less than this number of steps will be ignored as move and joined with the next movement
#define dropsegments  5

//-----------------------------------------------------------------------
// Machine UUID
//-----------------------------------------------------------------------
// This may be useful if you have multiple machines and wish to identify them by using the M115 command.
// By default we set it to zeros.
// Nutno se domluvit jestli to k necemu je
#define _DEF_CHAR_UUID "00000000-0000-0000-0000-000000000000"
#define _DEF_MACHINE_NAME "FIRMWARE_NAME: 3DFactories PROTOCOL_VERSION:1.02 MACHINE_TYPE:EASY3DMAKER EXTRUDER_COUNT:2"



//-----------------------------------------------------------------------
//// Planner buffer Size
//-----------------------------------------------------------------------

// The number of linear motions that can be in the plan at any give time
// if the SD Card need to much memory reduce the Values for Plannerpuffer (base of 2)
#ifdef SDSUPPORT
#define BLOCK_BUFFER_SIZE 16
#define BLOCK_BUFFER_MASK 0x0f
#else
#define BLOCK_BUFFER_SIZE 16
#define BLOCK_BUFFER_MASK 0x0f
#endif

//-----------------------------------------------------------------------
//// SETTINGS FOR ARC FUNCTION (Command G2/G2)
//-----------------------------------------------------------------------
/*
#define USE_ARC_FUNCTION
// Arc interpretation settings:
//Step to split a cirrcle in small Lines
#define MM_PER_ARC_SEGMENT 1
//After this count of steps a new SIN / COS caluclation is startet to correct the circle interpolation
#define N_ARC_CORRECTION 25
*/

//==============================================================================
//
// HEATER CONTROL AND PID PARAMETERS
//
//==============================================================================

// Select which extruder are used
#define BED_HEATER_ACTIVE
// musi byt definovano vzdy
#define EXT1_HEATER_ACTIVE
// definovano jen pokud je pouzit druhy extruder
//#define EXT2_HEATER_ACTIVE


//PID Controler Settings
#define PID_INTEGRAL_DRIVE_MAX 80 // too big, and heater will lag after changing temperature, too small and it might not compensate enough for long-term errors
#define PID_PGAIN 2560 //256 is 1.0  // value of X means that error of 1 degree is changing PWM duty by X, probably no need to go over 25
#define PID_IGAIN 64 //256 is 1.0  // value of X (e.g 0.25) means that each degree error over 1 sec (2 measurements) changes duty cycle by 2X (=0.5) units (verify?)
#define PID_DGAIN 4096 //256 is 1.0  // value of X means that around reached setpoint, each degree change over one measurement (half second) adjusts PWM by X units to compensate

// magic formula 1, to get approximate "zero error" PWM duty. Take few measurements with low PWM duty and make linear fit to get the formula
// for my makergear hot-end: linear fit {50,10},{60,20},{80,30},{105,50},{176,100},{128,64},{208,128}
#define HEATER_DUTY_FOR_SETPOINT(setpoint) ((int)((187L*(long)setpoint)>>8)-27)


//==============================================================
//
// FAN CONTROL
//
//==============================================================

// Odkomentovanim se aktivuje rizeni
#define FAN2_AS_CONTROLLERFAN

// Omezeni pwm pro extrudery, 255 = maximum trvale sepnuto
#define EXTRUDER_HEATER_CURRENT_MAX 255

// Omezeni pwm pro topeni desky, 255 == trvale sepnuto
#define BED_HEATER_CURRENT_MAX 255

// How often should the heater check for new temp readings, in milliseconds
#define HEATER_CHECK_INTERVAL 500
#define BED_CHECK_INTERVAL 5000

// Comment the following line to enable heat management during acceleration
#define DISABLE_CHECK_DURING_ACC
#ifndef DISABLE_CHECK_DURING_ACC
// Uncomment the following line to disable heat management during moves
//#define DISABLE_CHECK_DURING_MOVE
#endif

// Uncomment the following line to disable heat management during travel moves (and extruder-only moves, eg: retracts), strongly recommended if you are missing steps mid print.
// Probably this should remain commented if are using PID.
// It also defines the max milliseconds interval after which a travel move is not considered so for the sake of this feature.
#define DISABLE_CHECK_DURING_TRAVEL 1000

//// Temperature smoothing - only uncomment this if your temp readings are noisy (Gen6 without EvdZ's 5V hack)
//#define SMOOTHING
//#define SMOOTHFACTOR 16 //best to use a power of two here - determines how many values are averaged together by the smoothing algorithm


//// Experimental watchdog and minimal temp
// The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature
// If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109
//#define WATCHPERIOD 5000 //5 seconds

// Actual temperature must be close to target for this long before M109 returns success
//#define TEMP_RESIDENCY_TIME 20  // (seconds)
//#define TEMP_HYSTERESIS 5       // (C°) range of +/- temperatures considered "close" to the target one

//// The minimal temperature defines the temperature below which the heater will not be enabled
#define MINTEMP 5

//// Experimental max temp
// When temperature exceeds max temp, your heater will be switched off.
// This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure!
// You should use MINTEMP for thermistor short/failure protection.
#define MAXTEMP 275

// Select one of these only to define how the nozzle temp is read.
#define HEATER_USES_THERMISTOR
//#define HEATER_USES_AD595
//#define HEATER_USES_MAX6675

// Select one of these only to define how the bed temp is read.
#define BED_USES_THERMISTOR
#define EXTRUDER1_USE_THERMISTOR
#define EXTRUDER2_USE_THERMISTOR
//#define BED_USES_AD595


#define CONTROLLERFAN_SEC 60 //How many seconds, after all motors were disabled, the fan should run
#define EXTRUDERFAN_DEC 50 //Hotend temperature from where the fan will be turned on
//-----------------------------------------------------------------------
#define SEND_WRONG_CMD_INFO

#endif
//===============================================================================================================================================================
#if SYSTEM_CONFIG == 4

#define REMOTE_IO_SLAVE
//// Thermistor settings:
// 1 is 100k thermistor
// 2 is 200k thermistor
// 3 is mendel-parts thermistor
// 4 is 10k thermistor
// 5 is ParCan supplied 104GT-2 100K
// 6 is EPCOS 100k
// 7 is 100k Honeywell thermistor 135-104LAG-J01
#define THERMISTORHEATER 1
#define THERMISTORBED 1

//==============================================================================
//
// HEATER CONTROL AND PID PARAMETERS
//
//==============================================================================

// Select which extruder are used
#define BED_HEATER_ACTIVE
// musi byt definovano vzdy
#define EXT1_HEATER_ACTIVE
// definovano jen pokud je pouzit druhy extruder
#define EXT2_HEATER_ACTIVE


//PID Controler Settings
#define PID_INTEGRAL_DRIVE_MAX 80 // too big, and heater will lag after changing temperature, too small and it might not compensate enough for long-term errors
#define PID_PGAIN 2560 //256 is 1.0  // value of X means that error of 1 degree is changing PWM duty by X, probably no need to go over 25
#define PID_IGAIN 64 //256 is 1.0  // value of X (e.g 0.25) means that each degree error over 1 sec (2 measurements) changes duty cycle by 2X (=0.5) units (verify?)
#define PID_DGAIN 4096 //256 is 1.0  // value of X means that around reached setpoint, each degree change over one measurement (half second) adjusts PWM by X units to compensate

// magic formula 1, to get approximate "zero error" PWM duty. Take few measurements with low PWM duty and make linear fit to get the formula
// for my makergear hot-end: linear fit {50,10},{60,20},{80,30},{105,50},{176,100},{128,64},{208,128}
#define HEATER_DUTY_FOR_SETPOINT(setpoint) ((int)((187L*(long)setpoint)>>8)-27)


//==============================================================
//
// FAN CONTROL
//
//==============================================================

// Omezeni pwm pro extrudery, 255 = maximum trvale sepnuto
#define EXTRUDER_HEATER_CURRENT_MAX 255

// Omezeni pwm pro topeni desky, 255 == trvale sepnuto
#define BED_HEATER_CURRENT_MAX 255

// How often should the heater check for new temp readings, in milliseconds
#define HEATER_CHECK_INTERVAL 500
#define BED_CHECK_INTERVAL 5000

//// The minimal temperature defines the temperature below which the heater will not be enabled
#define MINTEMP 5

//// Experimental max temp
// When temperature exceeds max temp, your heater will be switched off.
// This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure!
// You should use MINTEMP for thermistor short/failure protection.
#define MAXTEMP 275

// Select one of these only to define how the nozzle temp is read.
#define HEATER_USES_THERMISTOR
//#define HEATER_USES_AD595
//#define HEATER_USES_MAX6675

// Select one of these only to define how the bed temp is read.
#define BED_USES_THERMISTOR
#define EXTRUDER1_USE_THERMISTOR
#define EXTRUDER2_USE_THERMISTOR
//#define BED_USES_AD595


#define CONTROLLERFAN_SEC 60 //How many seconds, after all motors were disabled, the fan should run
#define EXTRUDERFAN_DEC 50 //Hotend temperature from where the fan will be turned on

#endif
//===============================================================================================================================================================

